package com.liyi.caonima;

import com.liyi.caonima.Uitls.SqlSessionFactoryUtil;
import com.liyi.caonima.Uitls.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class many2onetest {
    private EmpoyeeMapper empoyeeMapper;
    private DepartmentMapper departmentMapper;

    public many2onetest(){
        empoyeeMapper = SqlSessionFactoryUtil.openSession().getMapper(EmpoyeeMapper.class);
        departmentMapper = SqlSessionFactoryUtil.openSession().getMapper(DepartmentMapper.class);
    }

    @Test
    public void testSave(){
        SqlSession session = SqlSessionFactoryUtil.openSession();

        empoyeeMapper = session.getMapper(EmpoyeeMapper.class);
        departmentMapper = session.getMapper(DepartmentMapper.class);


        Employee e = new Employee();
        e.setName("caonima");

        Department department = new Department();
        department.setName("你麻痹的好公司");
//        e.setDepartment(department);

        departmentMapper.add(department);
        empoyeeMapper.add(e);

        session.commit();
        session.close();
    }

    @Test
    public void testGet(){
        SqlSession session = SqlSessionFactoryUtil.openSession();
        departmentMapper = session.getMapper(DepartmentMapper.class);

        System.out.println(departmentMapper.get(2L));

    }

    @Test
    public void testList(){
        SqlSession session = SqlSessionFactoryUtil.openSession();
        empoyeeMapper = session.getMapper(EmpoyeeMapper.class);

//        System.out.println(empoyeeMapper.list());

    }
}
